#ifndef _GD25Q_HAL_H_
#define	_GD25Q_HAL_H_

#include "stdint.h"
#include "gd32f10x.h"

#ifdef _GD25Q_HAL_MODEL_
#define GD_EXT
#else
#define GD_EXT extern
#endif

#define GDSPI                                     SPI1

//WP# going low to protected the BP0~BP4 bits and SRP0~1 bits.
#define GD25WpEn()                                GPIOB->BCR=GPIO_DOR_DOR0
#define GD25WpDis()                               GPIOB->BOR=GPIO_DOR_DOR0   
//To re-start communication with chip, the HOLD# must be at high and then CS# must be at low
#define GD25Cs(x)                                 (x?(GPIOB->BOR=GPIO_DOR_DOR1 ):(GPIOB->BCR=GPIO_DOR_DOR1))
#define GD25Hold(x)                               (x?(GPIOA->BOR=GPIO_DOR_DOR4 ):(GPIOA->BCR=GPIO_DOR_DOR4))

GD_EXT uint32_t gd25qDmaEndSt;

void gdSpiInit(void);
uint8_t dgSpiRw(uint8_t dataW);
void gdSpiDma(uint8_t NewState);
void gdSpiDmaRw(uint8_t ModeRW, uint32_t  Len, uint8_t *Data);

#undef GD_EXT

#endif	/* _GD25Q_HAL_H_ */

